
#import "InfoView.h"

void handler(DPSTimedEntry teNumber, double now, void* userData)
{
	id obj = (id)userData;
	[obj animateDissolve];
}

@implementation InfoView
- initFrame:(const NXRect *)frameRect
{
	frontImageName = [NSString stringWithCString:"author"];
	backImageName = [NSString stringWithCString:"app"];
	return [super initFrame:frameRect];
}

- animate:sender
{
	[self removeTE];
	[self display];
	[window setDelegate:self];
	gray = 0.0;
	animateTE = DPSAddTimedEntry(.002, (DPSTimedEntryProc)handler, self, 
			NX_BASETHRESHOLD);
	return self;
}

- removeTE
{
	if(animateTE)
		{
			NSString* tmpString = frontImageName;
	
	  DPSRemoveTimedEntry(animateTE);
		 animateTE = 0;
		 frontImageName = backImageName;
		 backImageName = tmpString;
		}
	return self;
}

- windowWillClose:sender
{
	[self removeTE];
	return self;
}

- animateDissolve
{
	id image;

	[self lockFocus];
	image = [NXImage findImageNamed: [frontImageName cString]];
	[image dissolve:gray toPoint:&bounds];
	[self unlockFocus];
	[window flushWindow];
	NXPing();
	gray += 0.005;
	if( gray>1.0 )
		{
		 [self removeTE];
		}
	return self;
}

- mouseDown:(NXEvent*)theEvent
{
	[self animate:self];
	return [super mouseDown:theEvent];
}

- drawSelf:(const NXRect*)rects :(int)rectCount
{
	id image;

	PSsetgray(NX_LTGRAY);
	NXRectFill(&bounds);
	[self lockFocus];
	image = [NXImage findImageNamed:[backImageName cString]];
	[image composite:NX_SOVER toPoint:&bounds];
	[self unlockFocus];
	return self;
}
@end
